/*
 * Copyright (c) 2013 WDCY Information Technology Co. Ltd
 * www.wdcy.cc
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * WDCY Information Technology Co. Ltd ("Confidential Information").
 * You shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement you
 * entered into with WDCY Information Technology Co. Ltd.
 */
package com.monkey.web.platform.service;


import com.monkey.core.domain.auth.UserResourcePermission;
import com.monkey.core.domain.permission.Permission;
import com.monkey.core.domain.resource.Menu;
import com.monkey.core.domain.role.Role;
import com.monkey.core.domain.user.User;
import com.monkey.core.domain.user.UserStatus;
import com.monkey.core.plugin.dto.MonkeyDto;
import com.monkey.core.service.BaseService;
import com.monkey.core.web.response.MonkeyResponseDto;
import com.monkey.web.dto.request.user.ModifyUserPasswordDto;
import com.monkey.web.shiro.exception.UserBlockedException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import java.util.List;
import java.util.Set;

/**
 * @author Wu Tianqiang
 */
public interface UserService extends BaseService<User, Long> {

    /**
     * 新增user
     *
     * @param monkeyDto
     * @return
     */
    public void addUser(MonkeyDto monkeyDto);


    public boolean validAccountIsExist(String account);

    public boolean validEmailIsExist(String email);

    public boolean validMobileIsExist(String mobile);

    /**
     * 用户登录
     *
     * @param account
     * @param password
     * @return
     */
    public User login(String account, String password) throws UserBlockedException;


    /**
     * 在线用户信息
     *
     * @return
     */
    public MonkeyResponseDto onlineUsers();

    /**
     * 修改用户信息
     *
     * @param monkeyDto
     * @return
     */
    public void modifyUser(MonkeyDto monkeyDto);

    /**
     * 删除用户
     *
     * @param id
     * @return
     */
    public MonkeyResponseDto deleteUser(Long id);

    /**
     * 修改密码
     *
     * @param modifyUserPasswordDto
     * @return
     */
    public MonkeyResponseDto modifyPassword(ModifyUserPasswordDto modifyUserPasswordDto);

    /**
     * 改变用户状态
     *
     * @param ids
     * @param status
     * @param reason
     * @param opUser
     * @return
     */
    public void changeStatus(Long[] ids, UserStatus status, String reason, User opUser);


    public User findByAccount(String account);

    /**
     * 重置用户密码
     *
     * @param monkeyDto
     */
    void restPasswd(MonkeyDto monkeyDto);

    void grantPermissionToUser(User user, Menu menu, Long[] permissionIds);

    void recoveryPermissionFromUser(User user, Menu menu, Long[] permissionIds);

    List<Permission> getPermissionByUserMenu(User user, Menu menu);

    Page<UserResourcePermission> getPermissionByUser(User user, Pageable pageable);

    List<Role> getRolesByUser(User user);

    Set<String> findPermissions(Long userId);
}